package com.itheima.test4;

import java.util.Random;

public class RandomNumHandlerDemo {
    public static void main(String[] args) {
        useRandomNumHandler(new RandomNumHandler() {
            @Override
            public int getNumber() {
                Random random = new Random();
                int i = random.nextInt(10)+1;
                return i;
            }
        });

        useRandomNumHandler(()->{
            Random random = new Random();
            int i = random.nextInt(10)+1;
            return i;
        });
    }
        //如果Lamdba操作的接口中,有返回值,一定要通过return语句,将结果返回
    public static void useRandomNumHandler(RandomNumHandler randomNumHandler){
        int number = randomNumHandler.getNumber();
        System.out.println(number);
    }
}
interface RandomNumHandler{
    int getNumber();
}


